package com.ruoyi.tranShort.mqtt;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author wwy
 * @date 2021-08-10 16:55
 */
public class PropertiesUtils {
    public static Properties properties = new Properties();
    static {
        // 使用ClassLoader加载properties配置文件生成对应的输入流
        InputStream in = ResponseHandle.class.getClassLoader().getResourceAsStream("mqtt-wait-config.properties");
        // 使用properties对象加载输入流
        try {
            properties.load(in);
            //初始化配置
            init();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取值
     * @param key
     * @return
     */
    public static Object getValue(String key){
        Object o = properties.get(key);
        return o;
    }

    /**
     * 初始化配置
     */
    public static void init(){
        Object timeOutObject = properties.get("mqtt.wait.timeOut");
        if(timeOutObject != null){
            ResponseHandle.timeOut = Integer.valueOf(String.valueOf(timeOutObject));
        }
    }
}
